package NC;

import java.util.Arrays;

public class NC7 {

    public static int maxProfit (int[] prices) {
        if(prices==null || prices.length ==0) return 0;
        int min = prices[0];
        int ans = 0;
        for(int i:prices){
            if(i<min){
                min = i;
            }else {
                ans = Math.max(i-min,ans);
            }
        }
        return ans;
    }
}
